#include <iostream>
#include <pthread.h>
#include <string>
#include <unistd.h>

// int count = 0;
// void* run(void* args)
// {
//     std::string name = static_cast<const char*>(args);
//     while(1)
//     {
//         std::cout << name << " is running  " << count  << std::endl;
//         sleep(1);
//     }
//     return nullptr;

// }
// int main()
// {


//     pthread_t tid;
//     pthread_create(&tid,nullptr,run,(void*)"pthread_1");

//     //主线程
//     while (1)
//     {
//         count++;
//         std::cout << "main thread is running  " << count<<std::endl;
//         sleep(2);
//     }
//     pthread_join(tid, nullptr);

//     return 0;

// }

__thread int count = 0;
void* run(void* args)
{
    std::string name = static_cast<const char*>(args);
    while(1)
    {
        std::cout << name << " is running  " << pthread_self()  << std::endl;
        sleep(1);
    }
    return nullptr;

}
int main()
{


    pthread_t tid;
    pthread_create(&tid,nullptr,run,(void*)"pthread_1");

    //主线程
    while (1)
    {
        count++;
        std::cout << "main thread is running  " << tid<<std::endl;
        sleep(2);
    }
    pthread_join(tid, nullptr);

    return 0;

}